package org.ewaf.framework.workflow.activemq;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.ewaf.framework.workflow.message.WorkflowMessage;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class WorkflowMessageSender {

	private JmsTemplate  jmsTemplate;
	private WorkflowMessageConverter   messageConverter;
	
	
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}


	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}


	public WorkflowMessageConverter getMessageConverter() {
		return messageConverter;
	}


	public void setMessageConverter(WorkflowMessageConverter messageConverter) {
		this.messageConverter = messageConverter;
	}


	public void send(Destination  destination , final WorkflowMessage message){
		
		
		jmsTemplate.send(destination, new MessageCreator() {
			@Override
			public Message createMessage(Session session) throws JMSException {
				return messageConverter.toMessage(message, session);
			}
		});
		
	}
	
	
}
